#!/bin/bash

inf=$1
ito=${inf/.log/}_tdopt.log
itv=${inf/.log/}_tdvert.log

mkdir -p ${inf/.log/}_RMSD

# 处理 tdopt 文件夹中的文件
cd tdopt/
echo "Converting ${ito} to ${ito//log/xyz} ..."
Multiwfn ${ito} << EOF > /dev/null
100
2
2
${ito//log/xyz}
0
q
EOF

if [[ -f "${ito//log/xyz}" ]]; then
    mv ${ito//log/xyz} ../${inf/.log/}_RMSD
else
    echo "Error: ${ito//log/xyz} was not created in tdopt."
fi

wait

# 处理 tdvert 文件夹中的文件
cd ../tdvert/
echo "Converting ${itv} to ${itv//log/xyz} ..."
Multiwfn ${itv} << EOF > /dev/null
100
2
2
${itv//log/xyz}
0
q
EOF

if [[ -f "${itv//log/xyz}" ]]; then
    mv ${itv//log/xyz} ../${inf/.log/}_RMSD
else
    echo "Error: ${itv//log/xyz} was not created in tdvert."
fi

echo "xyz files have been moved to ${inf/.log/}_RMSD folder"

wait

cd ../${inf/.log/}_RMSD
cal_RMSD ${ito//log/xyz} ${itv//log/xyz} > ${ito//log/}_RSMD.txt
